package locality;

import static org.junit.Assert.*;

import java.util.ArrayList;

import genome.CGP;

import org.junit.Before;
import org.junit.Test;

public class ExpectedDistanceTest {

	private CGP g1;
	private CGP g2;
	private double[] default_input = {0.0,1.0};
	private int[] sample_genome1 = {0,0,0,1,1,1};
	private int[] sample_genome2 = {0,0,1,0,1,1};
	private int default_size = 6;
	
	private ExpectedDistance ed;
	
	
	@Before
	public void setUp() throws Exception {
		g1 = new CGP(default_input,default_size);
		g2 = new CGP(default_input,default_size);
		g1.genome=sample_genome1;
		g2.genome=sample_genome2;
		ed = new ExpectedDistance(g1,g2);
	}

	@Test
	public void testDiffConnectIndices() {
		ArrayList<Integer> diffs = ed.diffConnectIndices(g1, g2);
		assertTrue(diffs.get(0)==3);
		assertTrue(diffs.size()==1);
	}

	@Test
	public void testCalcExpectedDistance() {
		double fProd = 3; //F-1 ^ 1, one differing function value
		double mminus1Prod = Math.pow((1-CGP.MUTATION_RATE),4); //(1-m) ^ 2, two same differ between g1 and g2
		double cProd = 2; //1 differing connection, connects to 3 possible points, implies a value of two excluding connections to itself
		double mProd = Math.pow(CGP.MUTATION_RATE,2);
		
		double E = ed.calcExpectedDistance();
		System.out.println(E);
		assertTrue(E==(fProd*cProd)/(mminus1Prod*mProd));
	}
	
	@Test
	
	public void testExpectedDistanceEquation(){
		double E = ed.calcExpectedDistance();
		
		int n = 10000000;
		
		int nMutToG2 = 0;
		//ArrayList<CGP> samples = new ArrayList<CGP>();
		for (int i = 0; i < n; i++) {
			CGP gM = (CGP) g1.stoMutate();
			//samples.add(gM);
			//System.out.println(gM);
			if(gM.equals(g2)){
				nMutToG2 = nMutToG2+1;
			}
		}
		System.out.println(nMutToG2);
		System.out.println(n/E);
		System.out.println(g1);
	}

}
